< previous page page_132 next page >

Page 132
Puzzle 29
What Do You Do When It Mega Hurts?
QuickHow many processors are on the system where your application is running? How fast is the CPU? What do you do when Intel announces a problem with a particular run of processors and you need to determine the exact type, model, and stepping number of the CPU running your application?
Intel provides a DLL that lets you obtain all this information. It's called cpuinf32.dll and can be found on their Web site at http://developer.intel.com/vtune/cpuid/package.htm, where you will also find instructions for downloading the package.1
Now, before you get too excited about this cool little DLL, I must warn you that it works reliably only with Intel processors. Nevertheless, it poses a fascinating problem.
The DLL includes a function called cpuspeed, which can be used to determine the raw and normalized speeds of the CPU.2 The C declaration of the function is as follows:
struct FREQ_INFO cpuspeed(int clocks);
The clocks parameter should be set to 0 to use the default number of clock cycles for testing. The FREQ_INFO structure is defined as follows:
Type FREQ_INFO
   in_cycles As Long  ' Internal clock cycles during test
   ex_ticks As Long   ' Microseconds elapsed during test
   raw_freq As Long   ' Raw frequency of CPU in MHz
   norm_freq As Long  ' Normalized frequency of CPU in MHz
End Type
Care to try to come up with the correct declaration for this one?
7017a6ead0e3c4111b47a554df321e9f.gif 7017a6ead0e3c4111b47a554df321e9f.gif
1 At least, it's there at the time of publication. If it moves, you'll find the updated location at http://www.desaware.comonce we find it.
7017a6ead0e3c4111b47a554df321e9f.gif 7017a6ead0e3c4111b47a554df321e9f.gif
2 The normalized frequency is supposedly the nearest standard CPU frequency to the measured frequency. In practice, the number just seems to be the speed adjusted for rounding errors.

 
< previous page page_132 next page >